/*
  ID: nemokin1
  PROG: numtri
  LANG: C++
  using: truncate dfs, seems use too much time
*/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
 
using namespace std;
 
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=b;--i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define ALL(c) (c).begin(),(c).end()
 
#define debug(x) cerr<< #x << " = " << (x) << "\n";
#define debugv(v) cerr << #v << " = "; FOREACH(it,v) cerr << *it <<","; cerr << "\n";
#define SIZE(a)  (int(a.size()))
 
template<typename T> inline void checkMax(T& a, T b) {if (b>a) a=b;}
template<typename T> inline void checkMin(T& a, T b) {if (b<a) a=b;}
 
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef long double ld;
const int INF = 1000000000;

int maxsum = 0;
int N;
vector<vector<int> > v;

int dp[1001][1001];



    
int main() {
    freopen("numtri.in","r",stdin);freopen("numtri.out","w",stdout);
    cin >> N;
    for(int i = 1; i <= N; i++){
	vector<int> temp;
	for(int j = 0; j < i; j++){
	    int tt;
	    cin>>tt;
	    temp.push_back(tt);
	}
	v.push_back(temp);
    }
    dp[0][0] = v[0][0];
    
    for(int i = 1; i < v.size(); i++){
	for(int j = 0; j < v[i].size(); j++){
	    if(j-1 < 0) dp[i][j] = dp[i-1][j]+v[i][j];
	    else dp[i][j] = max(dp[i-1][j]+v[i][j], dp[i-1][j-1]+v[i][j]);
	}
    }
    for(int i = 0; i < v[N-1].size(); i++)
	checkMax(maxsum, dp[N-1][i]);
    cout << maxsum << endl;
    exit(0);
}
    
